import {BsStarFill, BsStar} from 'react-icons/bs'
import {history} from 'umi'

import './index.less'

function CollectionItem(props) {
  const data = props?.data?.cid ? props?.data?.comment : props?.data?.house

  return (
    <div className='collection-item'>
      <div className='title'>{props?.data?.cid ? '收藏论坛' : '收藏房屋'}</div>
      {props?.data?.cid ? <div className='info' onClick={() => {
        history.push({pathname: '/comment/comment', query: {id: props.data.cid}})
      }}>
        <img src={data?.pictures ? data?.pictures.split('|')[0] : require('@/assets/blank.png')}/>
        <div className='right'>
          <div className='name'>{data?.title}</div>
          <div className='content'>{data?.content}</div>
        </div>
      </div> : <div className='info' onClick={() => {
        history.push({pathname: '/house/house', query: {id: props.data.houseId}})
      }}>
        <img
          src={data?.houseInfo?.pictures ? data?.houseInfo?.pictures.split('|')[0] : require('@/assets/blank.png')}/>
        <div className='right'>
          <div className='name'>{data?.name}</div>
          <div className='content'>{data?.description}</div>
        </div>
      </div>}
      <div className='isCollect' onClick={() => {
        const temp = props?.data?.cid ? {cid: props?.data?.cid} : {houseId: props?.data?.houseId}
        props.handleClick(temp, props?.data?.isCollect, props?.index)
      }}>
        {props?.data?.isCollect ? <BsStarFill/> : <BsStar/>}
      </div>
    </div>
  )
}

export default CollectionItem
